<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="部门名称" prop="deptName">
        <el-input
          v-model="queryParams.deptName"
          placeholder="请输入部门名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="部门状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_normal_disable"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--<el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:dept:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-sort"
          size="mini"
          @click="toggleExpandAll"
        >展开/折叠</el-button>
      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table
      v-if="refreshTable"
      v-loading="loading"
      :data="deptList"
      row-key="deptId"
      :default-expand-all="isExpandAll"
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
    >
      <el-table-column prop="deptName" label="部门名称" width="260"></el-table-column>
      <el-table-column prop="orderNum" label="排序" width="200"></el-table-column>
      <el-table-column prop="status" label="状态" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="200">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-if="scope.row.level===2"
            @click="handleUpdateFactory(scope.row)"
            v-hasPermi="['system:dept:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-if="scope.row.level===3"
            @click="handleUpdateTeam(scope.row)"
            v-hasPermi="['system:dept:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-if="scope.row.level===4"
            @click="handleUpdateStation(scope.row)"
            v-hasPermi="['system:dept:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-plus"
            v-if="scope.row.level===1"
            @click="handleAddFactory(scope.row)"
            v-hasPermi="['system:dept:add']"
          >新增分厂</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-plus"
            v-if="scope.row.level===2"
            @click="handleAddTeam(scope.row)"
            v-hasPermi="['system:dept:add']"
          >新增班组</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-plus"
            v-if="scope.row.level===3"
            @click="handleAddStation(scope.row)"
            v-hasPermi="['system:dept:add']"
          >设站点</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-plus"
            v-if="scope.row.level===3 && scope.row.deptName!='包装组'"
            @click="handleSetStore(scope.row)"
            v-hasPermi="['system:dept:add']"
          >设入库班组</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-plus"
            v-if="scope.row.level===3"
            @click="handleSetSend(scope.row)"
            v-hasPermi="['system:dept:add']"
          >设发货班组</el-button>
          <el-button
            v-if="scope.row.parentId != 0"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:dept:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 添加或修改部门对话框 -->
    <el-dialog :title="title" :visible.sync="factoryopen" width="600px"  :close-on-click-modal ="false" append-to-body>
      <el-form ref="factoryform" :model="factoryform" :rules="factoryrules" label-width="80px" >
        <el-row>
          <el-col :span="24" v-if="factoryform.parentId !== 0">
            <el-form-item label="上级部门" prop="parentId" >
              <treeselect v-model="factoryform.parentId" :options="deptOptions" :normalizer="normalizer" placeholder="选择上级部门" :disabled="isDisabled" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="分厂名称" prop="deptName">
              <el-input v-model="factoryform.deptName" placeholder="请输入分厂名称" />
            </el-form-item>
          </el-col>
          <!--<el-col :span="12">
            <el-form-item label="分厂编码" prop="deptCode">
              <el-input v-model="teamform.deptCode" placeholder="请输入分厂编码" />
            </el-form-item>
          </el-col>-->
          <el-col :span="12">
            <el-form-item label="显示排序" prop="orderNum">
              <el-input-number v-model="factoryform.orderNum" controls-position="right" :min="0" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="负责人" prop="leader">
              <el-input v-model="factoryform.leader" placeholder="请输入负责人" maxlength="20" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="phone">
              <el-input v-model="factoryform.phone" placeholder="请输入联系电话" maxlength="11" />
            </el-form-item>
          </el-col>
        </el-row>
       <el-row >
         
          <!-- <el-col :span="12">
            <el-form-item label="邮箱" prop="email">
              <el-input v-model="form.email" placeholder="请输入邮箱" maxlength="50" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="部门状态">
              <el-radio-group v-model="form.status">
                <el-radio
                  v-for="dict in dict.type.sys_normal_disable"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>-->
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="factorysubmitForm">保 存</el-button>
        <el-button @click="factorycancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改部门对话框 -->
    <el-dialog :title="title" :visible.sync="teamopen" width="600px" :close-on-click-modal ="false" append-to-body>
      <el-form ref="teamform" :model="teamform" :rules="teamrules" label-width="100px">
        <el-row>
          <el-col :span="24" v-if="teamform.parentId !== 0">
            <el-form-item label="上级部门" prop="parentId" >
              <treeselect v-model="teamform.parentId" :options="deptOptions" :normalizer="normalizer" placeholder="选择上级部门" :disabled="isDisabled"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="班组名称" prop="deptName">
              <el-input v-model="teamform.deptName" placeholder="请输入班组名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="班组编码" prop="deptCode">
              <el-input v-model="teamform.deptCode" placeholder="请输入班组编码" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="周投料计划" prop="feedingFlag">
               <el-radio v-model="teamform.feedingFlag" label="0">否</el-radio>
               <el-radio v-model="teamform.feedingFlag" label="1">是</el-radio>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="负责人" prop="leader">
              <el-input v-model="teamform.leader" placeholder="请输入负责人" maxlength="20" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="联系电话" prop="phone">
              <el-input v-model="teamform.phone" placeholder="请输入联系电话" maxlength="11" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="显示排序" prop="orderNum">
              <el-input-number v-model="teamform.orderNum" controls-position="right" :min="0" />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
            <el-form-item label="邮箱" prop="email">
              <el-input v-model="form.email" placeholder="请输入邮箱" maxlength="50" />
            </el-form-item>
          </el-col>
         <el-col :span="12">
            <el-form-item label="部门状态">
              <el-radio-group v-model="form.status">
                <el-radio
                  v-for="dict in dict.type.sys_normal_disable"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>-->
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="teamsubmitForm">保 存</el-button>
        <el-button @click="teamcancel">取 消</el-button>
      </div>
    </el-dialog>

     <!-- 添加站点对话框 -->
     <el-dialog :title="title" :visible.sync="stationopen" width="600px" :close-on-click-modal ="false" append-to-body>
      <el-form ref="stationform" :model="stationform" :rules="stationrules" label-width="80px">
        <el-row>
          <el-col :span="24" v-if="stationform.parentId !== 0">
            <el-form-item label="上级部门" prop="parentId" >
              <treeselect v-model="stationform.parentId" :options="deptOptions" :normalizer="normalizer" placeholder="选择上级部门" :disabled="isDisabled"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="站点" prop="stationId">
              <el-select v-model="stationform.stationId" placeholder="请选择" filterable>
                <el-option
                  v-for="dict in stationinfoList"
                  :key="dict.id"
                  :label="dict.stationName"
                  :value="dict.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-table v-loading="loading" :data="teamstationList">
            <!--<el-table-column type="selection" width="55" align="center" />-->
            <el-table-column label="站点名称" align="center" prop="stationName" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDeleteStatioin(scope.row)"
                  v-hasPermi="['basic:teamstation:remove']"
                >删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="stationsubmitForm">保 存</el-button>
        <el-button @click="stationcancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 设置入库班组对话框 -->
    <el-dialog :title="title" :visible.sync="storeopen" width="600px" :close-on-click-modal ="false" append-to-body>
      <el-form ref="storeform" :model="storeform" :rules="storerules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="入库班组" prop="storeTeamId">
              <el-select v-model="storeform.storeTeamId" placeholder="请选择" filterable>
                <el-option
                  v-for="dict in storeTeamList"
                  :key="dict.deptId"
                  :label="dict.deptName"
                  :value="dict.deptId"
                ></el-option>
              </el-select>
               <!--<el-radio v-model="storeform.storeTeamFlag" label="0">本班组</el-radio>
               <el-radio v-model="storeform.storeTeamFlag" label="1">包装组</el-radio>-->
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="storesubmitForm">保 存</el-button>
        <el-button @click="storecancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 设置入库班组对话框 -->
    <el-dialog :title="title" :visible.sync="sendopen" width="600px" :close-on-click-modal ="false" append-to-body>
      <el-form ref="sendform" :model="sendform" :rules="sendrules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="发货班组" prop="sendTeamId">
              <el-select v-model="sendform.sendTeamId" placeholder="请选择" filterable>
                <el-option
                  v-for="dict in sendTeamList"
                  :key="dict.deptId"
                  :label="dict.deptName"
                  :value="dict.deptId"
                ></el-option>
              </el-select>
               <!--<el-radio v-model="storeform.storeTeamFlag" label="0">本班组</el-radio>
               <el-radio v-model="storeform.storeTeamFlag" label="1">包装组</el-radio>-->
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="sendsubmitForm">保 存</el-button>
        <el-button @click="sendcancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listDept, getDept, delDept, getStoreTeam,getSendTeam,addDept,editStoreTeam,updateDept, listDeptExcludeChild } from "@/api/system/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { listAllStationinfo } from "@/api/sm/basic/stationinfo";
import { listTeamstation, delTeamstation, addTeamstation } from "@/api/sm/basic/teamstation";
export default {
  name: "Dept",
  dicts: ['sys_normal_disable'],
  components: { Treeselect },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 表格树数据
      deptList: [],
      // 部门树选项
      deptOptions: [],
      storeTeamList: [],
      sendTeamList: [],
      stationinfoList: [],
      // 班组配置站点信息表格数据
      teamstationList: [],
      // 弹出层标题
      title: "",
      isDisabled: true,
      // 是否显示弹出层
      open: false,
      storeopen: false,
      sendopen: false,
      factoryopen: false,
      teamopen: false,
      stationopen: false,
      // 是否展开，默认全部展开
      isExpandAll: true,
      // 重新渲染表格状态
      refreshTable: true,
      // 查询参数
      queryParams: {
        deptName: undefined,
        status: undefined
      },
      // 表单参数
      form: {},
      factoryform: {
        deptId: undefined,
        parentId: undefined,
        deptName: undefined,
        deptCode: undefined,
        orderNum: undefined,
        leader: undefined,
        phone: undefined,
        email: undefined,
        status: "0",
        level: "2"
      },
      teamform: {
        deptId: undefined,
        parentId: undefined,
        deptName: undefined,
        deptCode: undefined,
        orderNum: undefined,
        leader: undefined,
        phone: undefined,
        email: undefined,
        feedingFlag: "0",
        status: "0",
        level: "2"
      },
      stationform: {
        teamId: undefined,
        parentId: undefined,
        stationId: undefined,
      },
      storeform: {
        teamId: undefined,
        storeTeamId: undefined
      },
      sendform: {
        teamId: undefined,
        sendTeamId: undefined
      },
      // 表单校验
      rules: {
        parentId: [
          { required: true, message: "上级部门不能为空", trigger: "blur" }
        ],
        deptName: [
          { required: true, message: "部门名称不能为空", trigger: "blur" }
        ],
        orderNum: [
          { required: true, message: "显示排序不能为空", trigger: "blur" }
        ],
        email: [
          {
            type: "email",
            message: "请输入正确的邮箱地址",
            trigger: ["blur", "change"]
          }
        ],
        phone: [
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur"
          }
        ]
      },
      factoryrules: {
        parentId: [
          { required: true, message: "上级部门不能为空", trigger: "blur" }
        ],
        deptName: [
          { required: true, message: "部门名称不能为空", trigger: "blur" }
        ],
        orderNum: [
          { required: true, message: "显示排序不能为空", trigger: "blur" }
        ],
        email: [
          {
            type: "email",
            message: "请输入正确的邮箱地址",
            trigger: ["blur", "change"]
          }
        ],
        phone: [
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur"
          }
        ]
      },
      stationrules: {
        parentId: [
          { required: true, message: "上级部门不能为空", trigger: "blur" }
        ],
        deptName: [
          { required: true, message: "部门名称不能为空", trigger: "blur" }
        ],
        orderNum: [
          { required: true, message: "显示排序不能为空", trigger: "blur" }
        ]
      },
      storerules: {
        storeTeamId: [
          { required: true, message: "入库组不能为空", trigger: "blur" }
        ],
      },
      sendrules: {
        sendTeamId: [
          { required: true, message: "发货组不能为空", trigger: "blur" }
        ],
      },
      teamrules: {
        parentId: [
          { required: true, message: "上级部门不能为空", trigger: "blur" }
        ],
        deptName: [
          { required: true, message: "部门名称不能为空", trigger: "blur" }
        ],
        orderNum: [
          { required: true, message: "显示排序不能为空", trigger: "blur" }
        ],
        email: [
          {
            type: "email",
            message: "请输入正确的邮箱地址",
            trigger: ["blur", "change"]
          }
        ],
        phone: [
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur"
          }
        ]
      }
    };
  },
  created() {
    this.getList();
    this.getStationList();
  },
  methods: {
    /** 查询班组配置站点信息列表 */
    getTeamStationList(teamId) {
      listTeamstation({"teamId":teamId}).then(response => {
        this.teamstationList = response.rows;
      });
    },
    /** 查询班组站点管理列表 */
    getStationList() {
      this.loading = true;
      listAllStationinfo().then(response => {
        this.stationinfoList = response.data;
        this.loading = false;
      });
    },
    /** 查询部门列表 */
    getList() {
      this.loading = true;
      listDept(this.queryParams).then(response => {
        this.deptList = this.handleTree(response.data, "deptId");
        this.loading = false;
      });
    },
    /** 转换部门数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.deptId,
        label: node.deptName,
        children: node.children
      };
    },
    storecancel() {
      this.storeopen = false;
      this.storereset();
    },
    sendcancel() {
      this.sendopen = false;
      this.sendreset();
    },
    stationcancel() {
      this.stationopen = false;
      this.stationreset();
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    factorycancel() {
      this.factoryopen = false;
      this.factoryreset();
    },
    teamcancel() {
      this.teamopen = false;
      this.teamreset();
    },
    // 表单重置
    reset() {
      this.form = {
        deptId: undefined,
        parentId: undefined,
        deptName: undefined,
        orderNum: undefined,
        leader: undefined,
        phone: undefined,
        email: undefined,
        status: "0",
        level: "1"
      };
      this.resetForm("form");
    },
    // 表单重置
    factoryreset() {
      this.factoryform = {
        deptId: undefined,
        parentId: undefined,
        deptName: undefined,
        orderNum: undefined,
        leader: undefined,
        phone: undefined,
        email: undefined,
        status: "0",
        level: "2"
      };
      this.resetForm("factoryform");
    },
    // 表单重置
    teamreset() {
      this.teamform = {
        deptId: undefined,
        parentId: undefined,
        deptName: undefined,
        orderNum: 1,
        leader: undefined,
        phone: undefined,
        email: undefined,
        feedingFlag: "0",
        status: "0",
        level: "3"
      };
      this.resetForm("teamform");
    },
    // 表单重置
    stationreset() {
      this.stationform = {
        teamId: undefined,
        parentId: undefined,
        stationId: undefined,
      };
      this.resetForm("stationform");
    },
    storereset() {
      this.storeform = {
        storeTeamId: undefined,
        deptId: undefined
      };
      this.resetForm("storeform");
    },
    sendreset() {
      this.sendform = {
        sendTeamId: undefined,
        deptId: undefined
      };
      this.resetForm("sendform");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 提交按钮 */
    storesubmitForm: function() {
      this.$refs["storeform"].validate(valid => {
        if (valid) {
          if (this.storeform.deptId != undefined) {
            editStoreTeam(this.storeform).then(response => {
              this.$modal.msgSuccess("设置成功");
              this.storeopen = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 提交按钮 */
    sendsubmitForm: function() {
      this.$refs["sendform"].validate(valid => {
        if (valid) {
          if (this.sendform.deptId != undefined) {
            editStoreTeam(this.sendform).then(response => {
              this.$modal.msgSuccess("设置成功");
              this.sendopen = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 新增按钮操作 */
    handleAdd(row) {
      this.reset();
      if (row != undefined) {
        this.form.parentId = row.deptId;
      }
      this.open = true;
      this.title = "添加部门";
      listDept().then(response => {
        this.deptOptions = this.handleTree(response.data, "deptId");
      });
    },
    handleAddFactory(row) {
      this.factoryreset();
      if (row != undefined) {
        this.factoryform.parentId = row.deptId;
      }
      this.factoryopen = true;
      this.title = "添加分厂";
      listDept().then(response => {
        this.deptOptions = this.handleTree(response.data, "deptId");
      });
    },
    handleAddTeam(row) {
      this.teamreset();
      if (row != undefined) {
        this.teamform.parentId = row.deptId;
      }
      this.teamopen = true;
      this.title = "添加班组";
      listDept().then(response => {
        this.deptOptions = this.handleTree(response.data, "deptId");
      });
    },
    handleAddStation(row) {
      this.stationreset();
      if (row != undefined) {
        this.stationform.parentId = row.deptId;
      }
      this.stationopen = true;
      this.title = "添加站点";
      listDept().then(response => {
        this.deptOptions = this.handleTree(response.data, "deptId");
        this.getTeamStationList(row.deptId);
      });
    },
    handleSetStore(row) {
      this.storereset();
      if (row != undefined) {
        this.storeform.deptId = row.deptId;
      }
      this.storeopen = true;
      this.title = "设入库班组";
      getStoreTeam(row.deptId).then(response => {
        this.storeform =response.data;
        this.getStoreTeamList(row.parentId);
      });
    },
    handleSetSend(row) {
      this.sendreset();
      if (row != undefined) {
        this.sendform.deptId = row.deptId;
      }
      this.sendopen = true;
      this.title = "设发货班组";
      getSendTeam(row.deptId).then(response => {
        this.sendform =response.data;
        this.getSendTeamList(row.parentId);
      });
    },
    getStoreTeamList(parentId){
      listDept({"parentId":parentId}).then(response => {
        this.storeTeamList = response.data;
      });
    },

    getSendTeamList(parentId){
      listDept({"parentId":parentId}).then(response => {
        this.sendTeamList = response.data;
      });
    },
    
    /** 展开/折叠操作 */
    toggleExpandAll() {
      this.refreshTable = false;
      this.isExpandAll = !this.isExpandAll;
      this.$nextTick(() => {
        this.refreshTable = true;
      });
    },
    
    /** 修改按钮操作 */
    handleUpdateFactory(row) {
      this.factoryreset();
      getDept(row.deptId).then(response => {
        this.factoryform = response.data;
        this.factoryopen = true;
        this.title = "修改分厂";
        listDeptExcludeChild(row.deptId).then(response => {
          this.deptOptions = this.handleTree(response.data, "deptId");
          if (this.deptOptions.length == 0) {
            const noResultsOptions = { deptId: this.factoryform.parentId, deptName: this.factoryform.parentName, children: [] };
            this.deptOptions.push(noResultsOptions);
          }
        });
      });
    },
    /** 修改按钮操作 */
    handleUpdateTeam(row) {
      this.teamreset();
      getDept(row.deptId).then(response => {
        this.teamform = response.data;
        this.teamopen = true;
        this.title = "修改班组";
        listDeptExcludeChild(row.deptId).then(response => {
          this.deptOptions = this.handleTree(response.data, "deptId");
          if (this.deptOptions.length == 0) {
            const noResultsOptions = { deptId: this.teamform.parentId, deptName: this.teamform.parentName, children: [] };
            this.deptOptions.push(noResultsOptions);
          }
        });
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      getDept(row.deptId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改部门";
        listDeptExcludeChild(row.deptId).then(response => {
          this.deptOptions = this.handleTree(response.data, "deptId");
          if (this.deptOptions.length == 0) {
            const noResultsOptions = { deptId: this.form.parentId, deptName: this.form.parentName, children: [] };
            this.deptOptions.push(noResultsOptions);
          }
        });
      });
    },
    
    stationsubmitForm: function() {
      this.$refs["stationform"].validate(valid => {
        if (valid) {
          this.stationform.teamId=this.stationform.parentId;
          addTeamstation(this.stationform).then(response => {
            this.$modal.msgSuccess("新增成功");
            this.stationopen = false;
            //this.getList();
          });
        }
      });
    },
    /** 提交按钮 */
    teamsubmitForm: function() {
      this.$refs["teamform"].validate(valid => {
        if (valid) {
          if (this.teamform.deptId != undefined) {
            updateDept(this.teamform).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.teamopen = false;
              this.getList();
            });
          } else {
            addDept(this.teamform).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.teamopen = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 提交按钮 */
    factorysubmitForm: function() {
      this.$refs["factoryform"].validate(valid => {
        if (valid) {
          if (this.factoryform.deptId != undefined) {
            updateDept(this.factoryform).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.factoryopen = false;
              this.getList();
            });
          } else {
            addDept(this.factoryform).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.factoryopen = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.deptId != undefined) {
            updateDept(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDept(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    handleDeleteStatioin(row) {
      this.$modal.confirm('是否确认删除该站点？').then(function() {
        return delTeamstation(row.id);
      }).then(() => {
        this.getTeamStationList(this.stationform.parentId);
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal.confirm('是否确认删除名称为"' + row.deptName + '"的数据项？').then(function() {
        return delDept(row.deptId);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    }
  }
};
</script>
